<?php

/**
 * Erra_Fields_Wysiwyg - Wysiwyg fields
 *
 * @package
 * @author Alexis Eric
 * @copyright Copyright (c) 2012 - Erra Prod
 * @version $1.0$
 * @access public
 */
class Erra_Fields_Wysiwyg extends Erra_Fields_Base_Field {

    public $cols = 30;
    public $rows = 15;

    function __construct($objectId, $cols = null, $rows = null) {
        parent::__construct($objectId);
        $this->cols = is_numeric($cols) ? $cols : $this->cols;
        $this->rows = is_numeric($rows) ? $rows : $this->rows;
        $this->height = 190;
    }

    public function editInstance(Array $extraProperties=null) {
        $res = '<div class="erra-form-field-instance">';
        $res .= $this->outputFieldHeader();
        
        $res .= '<textarea id="' . $this->getHtmlId() . '" cols="' . $this->cols . '" style="height:' . $this->height . 'px;"  name="' . $this->getHtmlName() . '" class="wysiwyg_editor">' . $this->getRawData() . ' </textarea>';
        $res .= '</div>';
        return $res;
    }

    function toHtml($displayParameters = null) {
        return $this->getRawData();
    }

    /**
     * Erra_Fields_Base_Field::_getRawData() - (internal) Returns raw data for this field
     *
     * @param mixed $lang
     * @return
     */
    public function _getRawData($lang = LANG) {
        if ($this->containsLocalizable(true) && !is_null($lang)) {
            return $this->_localizedInstances[$lang]->getRawData();
        }
        $output = wysiwyg_to_html($this->_rawData);
        return $output;
    }

    /** Getters and setters * */
    public function getCols() {
        return $this->cols;
    }

    public function setCols($cols) {
        $this->cols = $cols;
        return $this;
    }

    public function getRows() {
        return $this->rows;
    }

    public function setRows($rows) {
        $this->rows = $rows;
        return $this;
    }

}